const API_URL = import.meta.env.VITE_DEEPSEEK_API_URL
const API_KEY = import.meta.env.VITE_DEEPSEEK_API_KEY


export async function chatCompletion(messages, model) {
  try {
    const response = await fetch(`${API_URL}/chat/completions`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${API_KEY}`
      },
      body: JSON.stringify({
        model: model,
        messages: messages,
        stream: true
      })
    })

    if (!response.ok) {
      throw new Error(`API error: ${response.status}`)
    }

    return response.body
  } catch (error) {
    console.error('Chat completion error:', error)
    throw error
  }
} 